package com.tom.zx.controller;

import com.tom.zx.entity.User;
import com.tom.zx.service.IUserService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.security.Principal;
import java.util.HashMap;

/**
 * 负责页面路由
 *
 * @author 75073
 */
@Controller
@RequestMapping("/index")
@AllArgsConstructor
public class IndexController {

  private final IUserService userService;

  @ApiOperation("跳转 登录页")
  @GetMapping("/login")
  public String login() {
    return "login";
  }

  @ApiOperation("跳转 注册页")
  @GetMapping("/register")
  public String register() {
    return "register";
  }

  @ApiOperation("跳转 首页")
  @GetMapping({"/home", "/"})
  public String home(Model model, Principal principal) {
    HashMap<Object, Object> entity = new HashMap<>();
    entity.put("username", principal.getName());
    model.addAttribute("entity", entity);
    return "home";
  }

  @ApiOperation(value = "加载主页")
  @GetMapping("/main")
  public String main() {
    return "main";
  }

  @ApiOperation(value = "加载用户管理页面")
  @GetMapping("/user")
  public String user() {
    return "users/user";
  }

  @ApiOperation(value = "跳转 404 页面")
  @GetMapping("/404")
  public String error404() {
    return "error/404";
  }

  @ApiOperation(value = "跳转 403 页面")
  @GetMapping("/403")
  public String error403() {
    return "error/403";
  }

  @ApiOperation(value = "跳转 500 页面")
  @GetMapping("/500")
  public String error500() {
    return "error/500";
  }

  @ApiOperation(value = "跳转 菜单页")
  @GetMapping("/menu")
  public String menu() {
    return "menu/menu";
  }

  @ApiOperation(value = "跳转 角色页")
  @GetMapping("/role")
  public String role() {
    return "role/role";
  }

  @ApiOperation(value = "跳转到修改密码的页面")
  @GetMapping("/user/editPassword")
  public String changePassword() {
    return "users/edit_password";
  }

  @ApiOperation(value = "跳转到修改用户")
  @GetMapping("/user/updateSelfInfo")
  public String modifyUser(Model model, Principal principal) {
    User entity = userService.loadUserByUserName(principal.getName());
    model.addAttribute("entity", entity);
    return "users/user_edit";
  }

  @ApiOperation(value = "跳转到合同管理")
  @GetMapping("contract")
  public String announcement() {
    return "contract/contract";
  }

  @ApiModelProperty(value = "跳转到房屋信息管理")
  @GetMapping("houseInformation")
  public String houseInformation() {
    return "houseInformation/houseInformation";
  }

  @ApiOperation("跳转到装修方案页面")
  @GetMapping("decorationScheme")
  public String decorationScheme() {
    return "decorationScheme/decorationScheme";
  }


  @ApiOperation("跳转到装修订单页面")
  @GetMapping("furnishOrder")
  public String furnishOrder(){
    return "furnishOrder/furnishOrder";
  }

  @ApiOperation("录入房屋信息")
  @GetMapping("houseInformation/add")
  public String addHouseInformation(){
    return "houseInformation/add";
  }


  @ApiOperation("跳转到我的合同页面")
  @GetMapping("myContract")
  public  String myContract(){
    return "/contract/myContract";
  }

  @ApiOperation("跳转到装修方案选择")
  @GetMapping("decorationScheme/choose")
  public  String choose(){
    return  "decorationScheme/choose";
  }


  @ApiOperation("跳转到装修方案设计")
  @GetMapping("decorationScheme/add")
  public  String decorationSchemeAdd(){
    return "decorationScheme/add";
  }

  @ApiOperation("跳转到房屋信息查看")
  @GetMapping("houseInformation/list")
  public String houseInformationList(){
    return "houseInformation/list";
  }

  @ApiOperation("跳转到欢迎页")
  @GetMapping("welcome")
  public String welcome(){
    return  "welcome/index";
  }
}
